<?php
class BackendAdminAction extends BaseDBModel {

    public function __construct()
    {
        $this->tableName = 'admin_action';
    }

    /**
     * @param integer $admin_id
     * @param string $time
     * @param string $admin_role_name
     * @return integer
     */
    public function add($admin_id, $time, $admin_role_name)
    {
        return $this->insert(array('admin_id' => $admin_id, 'action_time' => $time, 'admin_role_name' => $admin_role_name));
    }

    /**
     * @param integer $admin_id
     * @return array
     */
    public function getActionOne($admin_id)
    {
        $sql = "SELECT t1.admin_id id, t1.action_time, t2.description, t3.email
                FROM admin_action AS t1
                LEFT JOIN admin_role AS t2 ON (t1.admin_role_name=t2.name)
                LEFT JOIN admin AS t3 ON (t1.admin_id=t3.id)
                WHERE t1.admin_id=:admin_id
                ORDER BY t1.action_time DESC";
        $command = $this->getCommand($sql);
        $command->bindParam(":admin_id", $admin_id, PDO::PARAM_INT);
        return $command->query();
    }

    /**
     * @return array
     */
    public function getAction()
    {
        $sql = "SELECT t1.admin_id id, t1.action_time, t2.description, t3.email
                FROM admin_action AS t1
                LEFT JOIN admin_role AS t2 ON (t1.admin_role_name=t2.name)
                LEFT JOIN admin AS t3 ON (t1.admin_id=t3.id)
                ORDER BY t1.action_time DESC";
        return $this->getCommand($sql)->query();
    }
}